//
//  SEGNeihborhoodDetailViewModel.m
//  Commom
//
//  Created by 梁学彰 on 2020/6/17.
//

#import "SEGNeihborhoodDetailViewModel.h"
#import "SEGShareHelpCardModel.h"

@interface SEGNeihborhoodDetailViewModel ()
@property (nonatomic, assign) BOOL isPraise;
@end

@implementation SEGNeihborhoodDetailViewModel
#pragma mark - life cycle
- (instancetype)init {
    if (self = [super init]) {
        [self initData];
        [self seg_creatDetailInfoCommand];
        [self seg_creatRequestQueryCommentsCommand];
        [self seg_creatChildCommentCellPraiseCommand];
        [self seg_creatDeleteCommentCommand];
        [self seg_creatPraiseCommand];
        [self seg_creatSendCommentCommand];
        [self seg_creatSellOutCommand];
        [self seg_creatDeleteCommand];
        
        self.praiseCommand.allowsConcurrentExecution = YES;
        self.childCommentCellPraiseCommand.allowsConcurrentExecution = YES;
    }
    return self;
}

- (void)dealloc {
    
}

#pragma mark - init
- (void)initData {
    self.pageNo = 1;
}

#pragma mark - send request
- (void)seg_creatDetailInfoCommand {
    @weakify(self);
    self.detailInfoCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);
            
            if (self.operationType == SEGNeighbourhoodOperationType_FowardPGC){// 转发pgc
                [self.sharedNewManager requestForwardWithObjType:self.objType objId:self.objId finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                    [subscriber sendNext:@(0)];
                    if (isSuccessed) {
                        self.userModel = self.sharedNewManager.fowardUserModel;
                        self.isMy = [self.userModel.userId isEqualToString:kAccountUserID];
                        [subscriber sendCompleted];
                    }else {
                        [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
                    }
                }];
            }else if (self.operationType == SEGNeighbourhoodOperationType_Market) {//集市
                [self.sHManager requestGetGoodsIdelBygoodsId:self.objId Finished:^(BOOL isSuccessed, NSString* codeType, NSString* errorMessage) {
                    [subscriber sendNext:@(0)];
                    if (isSuccessed) {
                        self.isMy = [ValueToString(self.sHManager.dataSourceGoodsIdel.userId) isEqualToString:kAccountUserID];
                        self.marketContent = [NSString stringWithFormat:@"%@，%@", self.sHManager.dataSourceGoodsIdel.title, self.sHManager.dataSourceGoodsIdel.exp];
                        self.userModel = [[SEGSharedCommonUserModel alloc] init];
                        self.userModel.userId = self.sHManager.dataSourceGoodsIdel.userId;
                        self.userModel.nickName = self.sHManager.dataSourceGoodsIdel.userName;
                        //                self.userModel.level = self.sHManager.dataSourceGoodsIdel.levelUrl;
                        self.userModel.icon = self.sHManager.dataSourceGoodsIdel.userIcon;
                        self.userModel.isAuth = self.sHManager.dataSourceGoodsIdel.isAuth;
                        self.userModel.sex = self.sHManager.dataSourceGoodsIdel.sex;
                        
                        
                        [subscriber sendCompleted];
                    }else {
                        [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
                    }
                }];
            }else { //帮帮 话题
                [self.helpManager requestQuizDetailByQuizId:self.objId Finished:^(BOOL isSuccessed, NSString* codeType, NSString* errorMessage) {
                    [subscriber sendNext:@(0)];
                    if (isSuccessed) {
                        self.isMy = [self.helpManager.dataSourceQuizDetail.userId isEqualToString:kAccountUserID];
                        
                        self.userModel = [[SEGSharedCommonUserModel alloc] init];
                        self.userModel.userId = self.helpManager.dataSourceQuizDetail.userId;
                        self.userModel.nickName = self.helpManager.dataSourceQuizDetail.userName;
                        //                self.userModel.level = self.helpManager.dataSourceQuizDetail.levelUrl;
                        self.userModel.icon = self.helpManager.dataSourceQuizDetail.ico;
                        self.userModel.isAuth = [self.helpManager.dataSourceQuizDetail.isAuth stringValue];
                        self.userModel.sex = [self.helpManager.dataSourceQuizDetail.sex stringValue];
                        [subscriber sendCompleted];
                    }else {
                        [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
                    }
                }];
            }
            
            return nil;
        }];
    }];
}

- (void)seg_creatRequestQueryCommentsCommand {
    @weakify(self);
    self.requestQueryCommentsCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);
            
            [self.sharedNewManager requestQueryCommentsWithObjId:self.objId objType:self.objType pageNo:[NSString stringWithFormat:@"%ld",(unsigned long)self.pageNo] pageLimit:@"10" finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                [subscriber sendNext:nil];
                if (isSuccessed) {
                    [subscriber sendCompleted];
                }else {
                    [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
                }
            }];
            
            return nil;
        }];
    }];
}

- (void)seg_creatChildCommentCellPraiseCommand {
    @weakify(self);
    self.childCommentCellPraiseCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(NSIndexPath *indexPath) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);
            
            SEGSharedCommentModel *model = self.sharedNewManager.commentsArray[indexPath.row];
            SEGSharedCommentInfoModel *infoModel = model.comment;
            SEGSharedCommonUserModel *userModel = model.user;
            if ([model.comment.isPraise isEqualToString:@"1"]) {
                //这里取消点赞行为方法
                [self.socialManager requestCancelPraiseByobjId:infoModel.id
                                                       objType:@"4"
                                                      Finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                    if (isSuccessed) {
                        infoModel.isPraise = @"0";
                        infoModel.praiseCount = [NSString stringWithFormat:@"%d",[infoModel.praiseCount intValue] - 1];
                        [subscriber sendCompleted];
                        if (self.delegate && [self.delegate respondsToSelector:@selector(refreshListViewWithIndex:isPraise:praiseCount:)]) {
                            [self.delegate refreshListViewWithIndex:self.index isPraise:infoModel.isPraise praiseCount:infoModel.praiseCount];
                        }
                    }else {
                        [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
                    }
                }];
            }else{
                //这里执行点赞行为方法
                [self.socialManager requestPraiseAttentByObjId:infoModel.id
                                                       ObjType:@"4"
                                               objPicUrlForMsg:nil
                                                objTitleForMsg:infoModel.content
                                                byReviewUserId:userModel.userId
                                                   parentObjId:self.objId
                                                 parentObjType:self.objType
                                                 operationType:[NSString stringWithFormat:@"%ld",(unsigned long)self.operationType]
                                                      isParent:@"2"
                                                      Finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                    if (isSuccessed) {
                        infoModel.isPraise = @"1";
                        infoModel.praiseCount = [NSString stringWithFormat:@"%d",[model.comment.praiseCount intValue] + 1];
                        
                        if (self.delegate && [self.delegate respondsToSelector:@selector(refreshListViewWithIndex:isPraise:praiseCount:)]) {
                            [self.delegate refreshListViewWithIndex:self.index isPraise:infoModel.isPraise praiseCount:infoModel.praiseCount];
                        }
                        [subscriber sendCompleted];
                    }else {
                        [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:200 userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
                    }
                }];
            }
            
            return nil;
        }];
    }];
}

- (void)seg_creatDeleteCommentCommand {
    @weakify(self);
    self.deleteCommentCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);
            
            //删除自己的评论
            NSString *objId;
            SEGSharedCommentModel *model = self.sharedNewManager.commentsArray[self.selectedIndexPath.row];
            if (self.selectChildIndex == -1) {
                objId = model.comment.id;
            }else {
                objId = model.comment.childComment[self.selectChildIndex].comment.id;
            }
            [self.sharedNewManager requestDeleteCommentWithCommentId:objId objType:model.comment.objType finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                if (isSuccessed) {
                    [subscriber sendCompleted];
                } else {
                    [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
                }
            }];
            
            return nil;
        }];
    }];
}

- (void)seg_creatPraiseCommand {
    @weakify(self);
    self.praiseCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        
        
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);
            
            //1：转发PGC、2：求助、3：集市、5：话题
            switch (self.operationType) {
                case SEGNeighbourhoodOperationType_FowardPGC:
                {
                    SEGSharedFowardModel* model = self.sharedNewManager.fowardInfoModel;
                    if ([model.isPraise isEqualToString:@"1"]) {
                        //这里取消点赞行为方法
                        [self.socialManager requestCancelPraiseByobjId:self.objId
                                                               objType:@"2"
                                                              Finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                            if (isSuccessed) {
                                model.isPraise = @"0";
                                model.praiseCount = [NSString stringWithFormat:@"%d",[model.praiseCount intValue] - 1];
                                RACTuple *tmp = RACTuplePack(model.isPraise,model.praiseCount);
                                [subscriber sendNext:tmp];
                                
                                [subscriber sendCompleted];
                                
                            }else {
                                [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:codeType.intValue userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
                                
                            }
                        }];
                    }else{
                        //这里执行点赞行为方法
                        [self.socialManager requestPraiseAttentByObjId:self.objId
                                                               ObjType:@"2"
                                                       objPicUrlForMsg:model.sharePicture
                                                        objTitleForMsg:model.shareContent
                                                        byReviewUserId:self.userModel.userId
                                                           parentObjId:self.objId
                                                         parentObjType:[NSString stringWithFormat:@"%ld",(unsigned long)SEGUserType_ACTIVITY]
                                                         operationType:[NSString stringWithFormat:@"%ld",(unsigned long)self.operationType]
                                                              isParent:@"1"
                                                              Finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                            if (isSuccessed) {
                                model.isPraise = @"1";
                                model.praiseCount = [NSString stringWithFormat:@"%d",[model.praiseCount intValue] + 1];
                                RACTuple *tmp = RACTuplePack(model.isPraise,model.praiseCount);
                                [subscriber sendNext:tmp];
                                
                                [subscriber sendCompleted];
                                
                                
                                
                            }else {
                                
                                [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:codeType.intValue userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
                            }
                        }];

                    }
                    break;
                }
                case SEGNeighbourhoodOperationType_Help: {
                    [subscriber sendCompleted];
                }
                case SEGNeighbourhoodOperationType_Topic:
                {
                    SEGFindQuizListByQuizTypeModel* model = self.helpManager.dataSourceQuizDetail;
                    
                    if ([[model.isParise stringValue]isEqualToString:@"1"]) {
                        //这里取消点赞行为方法
                        [self.socialManager requestCancelPraiseByobjId:self.objId
                                                               objType:@"2"
                                                              Finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                            if (isSuccessed) {
                                model.isParise = @(0);
                                model.praiseTotal = @([model.praiseTotal intValue] - 1);
                                
                                
                                RACTuple *tmp = RACTuplePack(ValueToString(model.isParise),ValueToString(model.praiseTotal));
                                [subscriber sendNext:tmp];
                                
                                [subscriber sendCompleted];
                                
                                
                                
                            }else {
                                
                                [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:codeType.intValue userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
                            }
                        }];
                    }else{
                        //这里执行点赞行为方法self.operationType == SEGNeighbourhoodOperationType_Topic ? [NSString stringWithFormat:@"%ld",(unsigned long)SEGUserType_ACTIVITY] : [NSString stringWithFormat:@"%ld",(unsigned long)SEGUserType_QUESTION]
                        [self.socialManager requestPraiseAttentByObjId:self.objId
                                                               ObjType:@"2"
                                                       objPicUrlForMsg:model.quizPic
                                                        objTitleForMsg:model.quizContent1
                                                        byReviewUserId:model.userId
                                                           parentObjId:self.objId
                                                         parentObjType:@"2"
                                                         operationType:[NSString stringWithFormat:@"%ld",(unsigned long)self.operationType]
                                                              isParent:@"1"
                                                              Finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                            if (isSuccessed) {
                                model.isParise = @(1);
                                model.praiseTotal = @([model.praiseTotal intValue] + 1);
                                RACTuple *tmp = RACTuplePack(ValueToString(model.isParise),ValueToString(model.praiseTotal));
                                [subscriber sendNext:tmp];
                                
                                [subscriber sendCompleted];
                                
                                
                                
                            }else {
                                [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:codeType.intValue userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
                            }
                        }];

                    }
                    break;
                }
                case SEGNeighbourhoodOperationType_Market:
                {
                    SEGQueryGoodsIdelModel* model = self.sHManager.dataSourceGoodsIdel;
                    if ([[self.sHManager.dataSourceGoodsIdel.isLike stringValue]isEqualToString:@"1"]) {
                        //这里取消点赞行为方法
                        [self.socialManager requestCancelPraiseByobjId:self.objId
                                                               objType:self.objType
                                                              Finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                            if (isSuccessed) {
                                model.isLike = @(0);
                                model.attenCount = @([model.attenCount intValue] - 1);
                                
                                RACTuple *tmp = RACTuplePack(ValueToString(model.isLike),ValueToString(model.attenCount));
                                [subscriber sendNext:tmp];
                                
                                [subscriber sendCompleted];
                                
                                
                            }else {
                                [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:codeType.intValue userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
                            }
                        }];
                    }else{
                        //这里执行点赞行为方法
                        [self.socialManager requestPraiseAttentByObjId:self.objId
                                                               ObjType:self.objType
                                                       objPicUrlForMsg:model.img1
                                                        objTitleForMsg:model.title
                                                        byReviewUserId:model.userId
                                                           parentObjId:model.goodsId
                                                         parentObjType:self.objType
                                                         operationType:[NSString stringWithFormat:@"%ld",(unsigned long)self.operationType]
                                                              isParent:@"1"
                                                              Finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                            if (isSuccessed) {
                                model.isLike = @(1);
                                model.attenCount = @([model.attenCount intValue] + 1);
                                RACTuple *tmp = RACTuplePack(ValueToString(model.isLike),ValueToString(model.attenCount));
                                [subscriber sendNext:tmp];
                                
                                [subscriber sendCompleted];
                                
                                
                                
                            }else {
                                [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:codeType.intValue userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
                            }
                        }];
                    }
                    break;
                }
                default:
                    break;
            }
            
            
            return nil;
        }];
    }];
}

- (void)seg_creatSendCommentCommand {
    @weakify(self);
    self.sendCommentCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(NSString *content) {
        @strongify(self);
        self.commentContent = content;
        return [self sendCommentByOption];
    }];
}

- (RACSignal *)sendCommentByOption {
    
    //当昵称为空时传入手机号码
    SEGProfileModel* sysAccount = [SEGProfileManager sharedManager].profile /*SAM:登录FUNC*/;
    NSString* nickName = sysAccount.nickname;
    if ([nickName length] == 0) {
        nickName = sysAccount.tel;
    }
    
    if (!self.selectedIndexPath) {//回复主贴
        switch (self.operationType) {
            case SEGNeighbourhoodOperationType_FowardPGC:
            {
                return [self seg_commentForwardPGCWithNickName:nickName];
                break;
            }
            case SEGNeighbourhoodOperationType_Help:
            case SEGNeighbourhoodOperationType_Topic:
            {
                return [self seg_commentHelpOrTopicWithNickName:nickName];
                break;
            }
            case SEGNeighbourhoodOperationType_Market:
            {
                return [self seg_commentMarketWithNickName:nickName];
                break;
            }
            default:
                break;
        }
    }else {
        switch (self.operationType) {
            case SEGNeighbourhoodOperationType_FowardPGC:
            case SEGNeighbourhoodOperationType_Help:
            case SEGNeighbourhoodOperationType_Topic:
            {
                return [self seg_commentToChildComment];
                break;
            }
            case SEGNeighbourhoodOperationType_Market:
            {
                return [self seg_commentMarketChildCommentWithNickName:nickName];
                break;
            }
            default:
                break;
        }
    }
    return nil;
}

- (void)seg_creatSellOutCommand {
    @weakify(self);
    self.sellOutCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);
            
            [self.sHManager requestUpdateStatusBygoodsId:self.objId
                                                 objType:self.objType
                                                  status:[NSString stringWithFormat:@"%lu",(unsigned long)SEGEnumIdleStatus_SaleOut]
                                                Finished:^(BOOL isSuccessed, NSString* codeType, NSString* errorMessage) {
                [subscriber sendNext:@(0)];
                [SEGAlertView showTmepMessageWithMessage:errorMessage];
                if (isSuccessed) {
                    [subscriber sendCompleted];
                }else {
                    [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
                }
            }];
            
            return nil;
        }];
    }];
}

- (void)seg_creatDeleteCommand {
    @weakify(self);
    self.deleteCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            @strongify(self);
            
            if (self.operationType == SEGNeighbourhoodOperationType_Market) {//老接口
                [subscriber sendNext:@(1)];
                [self.sHManager requestUpdateStatusBygoodsId:self.objId
                                                     objType:self.objType
                                                      status:[NSString stringWithFormat:@"%lu",(unsigned long)SEGEnumIdleStatus_Remove]
                                                    Finished:^(BOOL isSuccessed, NSString* codeType, NSString* errorMessage) {
                    [subscriber sendNext:@(0)];
                    if (isSuccessed) {
                        [subscriber sendCompleted];
                    }else {
                        [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
                    }
                }];
            }else {
                [subscriber sendNext:@(1)];
                [self.sharedNewManager requestDeleteJoinHistoryWithObjId:self.objId
                                                                 objType:self.objType
                                                                finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                    [subscriber sendNext:@(0)];
                    if (isSuccessed) {
                        [subscriber sendCompleted];
                    }else {
                        [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
                    }
                }];
            }
            
            return nil;
        }];
    }];
}






#pragma mark - event response
- (void)analyticsActionWithObjName:(NSString *)objName {
}

- (NSString *)seg_initShareParamsWithDic:(NSMutableDictionary *)params {
    
    
    
    
    
    NSString *shareContent;
    NSString *shareImageUrl;
    NSArray *otherActionTypesArr;
    if (self.operationType == SEGNeighbourhoodOperationType_FowardPGC){// 转发pgc
        shareContent = self.sharedNewManager.fowardInfoModel.shareContent;
        shareImageUrl = @"";//self.sharedNewManager.fowardInfoModel.sharePicture;
        if (self.isMy) {
            otherActionTypesArr = @[@(SEGShareVCActionType_Delete)];
        }
        [params setValue:@(SEGShareVCType_Help) forKey:@"shareVCType"];
        [params setValue:@"2" forKey:@"objSection"];
    }else if (self.operationType == SEGNeighbourhoodOperationType_Market) {//集市
        shareContent = self.marketContent;
        NSArray *picArray = [self.sHManager.dataSourceGoodsIdel.img1 componentsSeparatedByString:@","];
        NSMutableArray *array = [NSMutableArray array];
        [picArray enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (obj.length > 0) {
                [array addObject:obj];
            }
        }];
        if (picArray.count > 0) {
            shareImageUrl = picArray[0];
        }
        
        if (self.isMy) {
            switch ([self.sHManager.dataSourceGoodsIdel.status integerValue]) {
                case SEGEnumIdleStatus_Idle:
                {
                    otherActionTypesArr = @[@(SEGShareVCActionType_Edit), @(SEGShareVCActionType_SellOut), @(SEGShareVCActionType_Delete)];
                    break;
                }
                case SEGEnumIdleStatus_SaleOut:
                {
                    otherActionTypesArr = @[@(SEGShareVCActionType_Again), @(SEGShareVCActionType_Delete)];
                    break;
                }
                case SEGEnumIdleStatus_Remove:{
                }
                    break;
            }
        }
        [params setValue:@(SEGShareVCType_Market) forKey:@"shareVCType"];
        [params setValue:[SEGBasicBussinessEnums getSectionWithObjType:self.objType] forKey:@"objSection"];
    }else { //帮帮 话题
        shareContent = self.helpManager.dataSourceQuizDetail.quizContent1;
        if (self.helpManager.dataSourceQuizDetail.quizPic.length > 0) {
            NSArray *tempArray = [self.helpManager.dataSourceQuizDetail.quizPic componentsSeparatedByString:@","];
            NSMutableArray *picArray = [NSMutableArray array];
            [tempArray enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if (obj.length > 0) {
                    [picArray addObject:obj];
                }
            }];
            shareImageUrl  = picArray[0];
        }
        if (self.isMy) {
            otherActionTypesArr = @[@(SEGShareVCActionType_Delete)];
        }
        [params setValue:@(SEGShareVCType_Help) forKey:@"shareVCType"];
        if (self.operationType == SEGNeighbourhoodOperationType_Help) {
            [params setValue:@"1" forKey:@"objSection"];
            // 区分求助类型
            if ([self.helpManager.dataSourceQuizDetail.isBroadCast integerValue] > 0) {//求助卡
                SEGShareHelpCardModel *model = [[SEGShareHelpCardModel alloc] init];
                model.helpType = self.helpManager.dataSourceQuizDetail.labelName;
                model.helpContent = self.helpManager.dataSourceQuizDetail.quizContent1;
                model.contact = self.helpManager.dataSourceQuizDetail.contacts;
                model.contactInformation = self.helpManager.dataSourceQuizDetail.tel;
                if (self.helpManager.dataSourceQuizDetail.quizPicArr.count > 0) {
                    // TODO: Wendy, 获取cell的图片
                    //                    SEGNewCommentCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
                    //                    UIImageView *imageView = [cell.varcustomContentView.neighbourView.morePicture subviews][0];
                    //                    model.image = imageView.image;
                    //
                    ////                    NSString *imageUrl = self.helpManager.dataSourceQuizDetail.quizPicArr[0];
                    ////                    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]];
                    ////                    model.image = image;
                }
                [params setValue:model forKey:@"helpCardModel"];
            }
        }else {
            [params setValue:@"3" forKey:@"objSection"];
            [params setValue:[NSArray array] forKey:@"shareTypesArr"];//话题没有分享的所有类型
        }
    }
    
    if (shareImageUrl && shareImageUrl.length > 0) {
        NSString *imageUrl = [NSString stringWithFormat:@"%@%@",kClientSmallImageRootURL,shareImageUrl];
        UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]];
        [params setValue:image forKey:@"shareImage"];
    }
    
    NSString *shareTitle = [NSString stringWithFormat:@"“%@”发布了一条动态信息",self.userModel.nickName];
    NSString* shareUrlString = [NSString stringWithFormat:@"%@%@?#/ugc?objId=%@&objType=%@&operationType=%@&app_platform_code=%@&company_platform_code=%@&scheme=%@", kClientRootURL, kNewShareURLPre, self.objId, self.objType, @(self.operationType), kAppPlatformCode, kAppPlatformCode, kOpenAppScheme];
    [params setValue:self.objId forKey:@"objID"];
    
    //添加举报按钮
    if (!self.isMy) {
        NSMutableArray *temp = [NSMutableArray arrayWithArray:otherActionTypesArr];
        //        [temp addObject:@(SEGShareVCActionType_NotIntersting)];//详情没有不感兴趣
        [temp addObject:@(SEGShareVCActionType_Report)];
        [params setValue:temp forKey:@"otherActionTypesArr"];
    }else {
        [params setValue:otherActionTypesArr forKey:@"otherActionTypesArr"];
    }
    
    [params setValue:shareTitle forKey:@"sharetitle"];
    [params setValue:shareContent forKey:@"sharecontent"];
    [params setValue:shareUrlString forKey:@"inviteurl"];
    return shareContent;
}


#pragma mark - 评论方法
- (RACSignal *)seg_commentForwardPGCWithNickName:(NSString *)nickName {
    @weakify(self);
    RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        @strongify(self);
        
        if(!self.sharedNewManager.fowardInfoModel.sharePicture || !self.userModel) {
            [subscriber sendCompleted];
            return nil;
        }
        [subscriber sendNext:@(1)];
        [self.sharedNewManager requestSaveQuizAnswerByquizId:self.objId
                                                 answContent:self.commentContent
                                                     creator:nickName
                                                  byReviewId:nil
                                                byReviewNick:nil
                                              byReviewUserId:self.userModel.userId
                                               objSendUserId:self.userModel.userId
                                             objPicUrlForMsg:self.sharedNewManager.fowardInfoModel.sharePicture
                                              objTitleForMsg:self.sharedNewManager.fowardInfoModel.shareContent
                                                    objeType:self.sharedNewManager.fowardInfoModel.objType
                                                 parentObjId:self.objId
                                               parentObjType:SEGUserType_QUESTION
                                               operationType:[NSString stringWithFormat:@"%ld",(unsigned long)self.operationType]
                                             sourceCommentId:nil
                                                    isParent:@"1"
                                                    Finished:^(BOOL isSuccessed, NSString* codeType, NSString* errorMessage) {
            RACTuple *tmp = RACTuplePack(@(isSuccessed),codeType,errorMessage,@(YES));
            [subscriber sendNext:tmp];
            [subscriber sendCompleted];
        }];
        
        return nil;
    }];
    return signal;
    
    
}

- (RACSignal *)seg_commentHelpOrTopicWithNickName:(NSString *)nickName {
    @weakify(self);
    RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        @strongify(self);
        
        if(!self.helpManager.dataSourceQuizDetail) {
            [subscriber sendCompleted];
            return nil;
        }
        [subscriber sendNext:@(1)];
        [self.sharedNewManager requestSaveQuizAnswerByquizId:self.objId
                                                 answContent:self.commentContent
                                                     creator:nickName
                                                  byReviewId:nil
                                                byReviewNick:nil
                                              byReviewUserId:self.helpManager.dataSourceQuizDetail.userId
                                               objSendUserId:self.helpManager.dataSourceQuizDetail.userId
                                             objPicUrlForMsg:self.helpManager.dataSourceQuizDetail.quizPic
                                              objTitleForMsg:self.helpManager.dataSourceQuizDetail.quizContent1
                                                    objeType:self.helpManager.dataSourceQuizDetail.objType
                                                 parentObjId:self.objId
                                               parentObjType:self.operationType == SEGNeighbourhoodOperationType_Topic ? SEGUserType_ACTIVITY : SEGUserType_QUESTION
                                               operationType:[NSString stringWithFormat:@"%ld",(unsigned long)self.operationType]
                                             sourceCommentId:nil
                                                    isParent:@"1"
                                                    Finished:^(BOOL isSuccessed, NSString* codeType, NSString* errorMessage) {
            
            RACTuple *tmp = RACTuplePack(@(isSuccessed),codeType,errorMessage,@(YES));
            [subscriber sendNext:tmp];
            [subscriber sendCompleted];
        }];
        
        return nil;
    }];
    return signal;
    
}

- (RACSignal *)seg_commentMarketWithNickName:(NSString *)nickName {
    @weakify(self);
    RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        @strongify(self);
        
        if(!self.sHManager.dataSourceGoodsIdel) {
            [subscriber sendCompleted];
            return nil;
        }
        [subscriber sendNext:@(1)];
        [self.sharedNewManager requestCommentSaveByobjId:self.objId
                                                 objType:self.objType
                                          commentContent:self.commentContent
                                                 creator:kAccountNickName
                                              byReviewId:nil
                                            byReviewNick:nil
                                          byReviewUserId:self.sHManager.dataSourceGoodsIdel.userId
                                         objPicUrlForMsg:self.sHManager.dataSourceGoodsIdel.img1
                                          objTitleForMsg:self.sHManager.dataSourceGoodsIdel.title
                                             parentObjId:self.sHManager.dataSourceGoodsIdel.goodsId
                                           parentObjType:[self.objType integerValue]
                                           operationType:[NSString stringWithFormat:@"%ld",(unsigned long)self.operationType]
                                         sourceCommentId:nil
                                                isParent:@"1"
                                                Finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
            RACTuple *tmp = RACTuplePack(@(isSuccessed),codeType,errorMessage,@(YES));
            [subscriber sendNext:tmp];
            [subscriber sendCompleted];
        }];
        
        return nil;
    }];
    return signal;
    
}

#pragma mark 回复子评论
- (RACSignal *)seg_commentToChildComment {
    @weakify(self);
    RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        @strongify(self);
        
        if (self.sharedNewManager.commentsArray.count <= self.selectedIndexPath.row) {
            [subscriber sendCompleted];
            return nil;
        }
        [subscriber sendNext:@(1)];
        
        SEGSharedCommentModel *model = self.sharedNewManager.commentsArray[self.selectedIndexPath.row];
        if (self.selectChildIndex == -1) {//对子评论的主体回复
            [self.sharedNewManager requestSaveQuizAnswerByquizId:self.objId
                                                     answContent:self.commentContent
                                                         creator:kAccountNickName
                                                      byReviewId:model.comment.id
                                                    byReviewNick:model.user.nickName
                                                  byReviewUserId:model.user.userId
                                                   objSendUserId:kAccountUserID
                                                 objPicUrlForMsg:@""
                                                  objTitleForMsg:model.comment.content
                                                        objeType:model.comment.objType
                                                     parentObjId:self.objId
                                                   parentObjType:self.operationType == SEGNeighbourhoodOperationType_Topic ? SEGUserType_ACTIVITY : SEGUserType_QUESTION
                                                   operationType:[NSString stringWithFormat:@"%ld",(unsigned long)self.operationType]
                                                 sourceCommentId:model.comment.id
                                                        isParent:@"2"
                                                        Finished:^(BOOL isSuccessed, NSString* codeType, NSString* errorMessage) {
                RACTuple *tmp = RACTuplePack(@(isSuccessed),codeType,errorMessage,@(NO));
                [subscriber sendNext:tmp];
                [subscriber sendCompleted];
            }];
            //        byReviewId = model.comment.id;
            //        content = model.comment.content;
        }else {
            SEGSharedCommentChildCommentModel*childModel = model.comment.childComment[self.selectChildIndex];
            [self.sharedNewManager requestSaveQuizAnswerByquizId:self.objId
                                                     answContent:self.commentContent
                                                         creator:kAccountNickName
                                                      byReviewId:childModel.comment.id
                                                    byReviewNick:childModel.user.nickName
                                                  byReviewUserId:childModel.user.userId
                                                   objSendUserId:kAccountUserID
                                                 objPicUrlForMsg:@""
                                                  objTitleForMsg:childModel.comment.content
                                                        objeType:model.comment.objType
                                                     parentObjId:self.objId
                                                   parentObjType:self.operationType == SEGNeighbourhoodOperationType_Topic ? SEGUserType_ACTIVITY : SEGUserType_QUESTION
                                                   operationType:[NSString stringWithFormat:@"%ld",(unsigned long)self.operationType]
                                                 sourceCommentId:model.comment.id
                                                        isParent:@"2"
                                                        Finished:^(BOOL isSuccessed, NSString* codeType, NSString* errorMessage) {
                RACTuple *tmp = RACTuplePack(@(isSuccessed),codeType,errorMessage,@(NO));
                [subscriber sendNext:tmp];
                [subscriber sendCompleted];
            }];
            //        byReviewId = childModel.comment.id;
            //        content = childModel.comment.content;
        }
        
        return nil;
    }];
    return signal;
    
    
}

- (RACSignal *)seg_commentMarketChildCommentWithNickName:(NSString *)nickName {
    @weakify(self);
    RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        @strongify(self);
        
        if (self.sharedNewManager.commentsArray.count <= self.selectedIndexPath.row) {
            [subscriber sendCompleted];
            return nil;
        }
        [subscriber sendNext:@(1)];
        //    NSString *byReviewId;
        //    NSString *content;
        SEGSharedCommentModel *model = self.sharedNewManager.commentsArray[self.selectedIndexPath.row];
        if (self.selectChildIndex == -1) {//对子评论的主体回复
            [self.sharedNewManager requestCommentSaveByobjId:self.objId
                                                     objType:self.objType
                                              commentContent:self.commentContent
                                                     creator:kAccountNickName
                                                  byReviewId:model.comment.id
                                                byReviewNick:model.user.nickName
                                              byReviewUserId:model.user.userId
                                             objPicUrlForMsg:nil
                                              objTitleForMsg:model.comment.content
                                                 parentObjId:self.objId
                                               parentObjType:[self.objType integerValue]
                                               operationType:[NSString stringWithFormat:@"%ld",(unsigned long)self.operationType]
                                             sourceCommentId:model.comment.id
                                                    isParent:@"2"
                                                    Finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                RACTuple *tmp = RACTuplePack(@(isSuccessed),codeType,errorMessage,@(NO));
                [subscriber sendNext:tmp];
                [subscriber sendCompleted];
            }];
            //        byReviewId = model.comment.id;
            //        content = model.comment.content;
        }else {
            SEGSharedCommentChildCommentModel*childModel = model.comment.childComment[self.selectChildIndex];
            [self.sharedNewManager requestCommentSaveByobjId:self.objId
                                                     objType:self.objType
                                              commentContent:self.commentContent
                                                     creator:kAccountNickName
                                                  byReviewId:childModel.comment.id
                                                byReviewNick:childModel.user.nickName
                                              byReviewUserId:childModel.user.userId
                                             objPicUrlForMsg:nil
                                              objTitleForMsg:childModel.comment.content
                                                 parentObjId:self.objId
                                               parentObjType:[self.objType integerValue]
                                               operationType:[NSString stringWithFormat:@"%ld",(unsigned long)self.operationType]
                                             sourceCommentId:model.comment.id
                                                    isParent:@"2"
                                                    Finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
                RACTuple *tmp = RACTuplePack(@(isSuccessed),codeType,errorMessage,@(NO));
                [subscriber sendNext:tmp];
                [subscriber sendCompleted];
            }];
            //        byReviewId = childModel.comment.id;
            //        content = childModel.comment.content;
        }
        
        return nil;
    }];
    return signal;
    
    
}


#pragma mark - setter and getter

- (SEGSharedNewManager *)sharedNewManager {
    if (!_sharedNewManager) {
        _sharedNewManager = [[SEGSharedNewManager alloc] init];
    }
    return _sharedNewManager;
}

- (SEGHelpManager*)helpManager {
    if (!_helpManager) {
        _helpManager = [[SEGHelpManager alloc] init];
    }
    return _helpManager;
}

- (SEGSHManager*)sHManager {
    if (!_sHManager) {
        _sHManager = [[SEGSHManager alloc] init];
    }
    return _sHManager;
}

- (SEGCommunitySocialManager *)socialManager {
    if (!_socialManager) {
        _socialManager = [[SEGCommunitySocialManager alloc] init];
    }
    return _socialManager;
}

- (void)setObjId:(NSString *)objId {
    _objId = ValueToString(objId);
}

- (NSMutableDictionary *)cellHightDict {
    if (!_cellHightDict) _cellHightDict = [NSMutableDictionary new];
    return _cellHightDict;
}
@end
